package com.example.myapplication;

import android.app.Application;

import androidx.appcompat.app.AppCompatDelegate;

import com.example.baselibs.AppConfig;
import com.example.baselibs.BaseApplication;
import com.example.myapplication.shortvideo.utils.DisplayUtils;

/**
 * @author: rongfeng
 * @date: 2020/6/16
 * @description
 */
public class AppApplication extends BaseApplication {
    private static AppApplication sInstance;

    public AppApplication() {
        sInstance = this;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        DisplayUtils.init(this);
    }

    @Override
    public void initModuleApp(Application application) {
        for (String moduleApp : AppConfig.moduleApps) {
            try {
                Class clazz = Class.forName( moduleApp);
                BaseApplication baseApp = (BaseApplication) clazz.newInstance();
                baseApp.initModuleApp(this);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * @return App 全局上下文
     */
    public static AppApplication getInstance() {
        return sInstance;
    }
}
